""" Custom filters for Django / AppEngine template filters """

from google.appengine.ext import webapp 

register = webapp.template.create_template_register() 

@register.filter
def remove_underscore(value):
  """ Replaces underscores with whitespace """
  return value.replace('_',' ')

@register.filter
def property_print(value):
  """ Detects what kind of property this looks like and prints accordingly """
  if not value:
    return ''
  if isinstance(value, list) or isinstance(value, tuple):
    import logging; logging.info(value)
    return ', '.join(value)
  # Default is title case
  return value

@register.filter
def has(value, arg):
  return arg in value
  
@register.filter
def get(value, arg):
  return value.get(arg, None)
